package adpter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.hjh.qinxin.R;

import java.util.List;

import model.HotListModel;

public class HotListAdapter extends RecyclerView.Adapter<HotListAdapter.HotListHolder> {
    private Context context;
    public List<HotListModel> data;
    private OnRecyclerViewItemClickListener listener;

    public void setData(List<HotListModel> data){
        this.data = data;
    }
    public HotListAdapter(Context context){
        this.context = context;
    }
    @Override
    public HotListHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType){
        return new HotListHolder(LayoutInflater.from(context). inflate(R.layout.hot_list_item,null));
    }

    @Override
    public void onBindViewHolder(@NonNull  HotListAdapter.HotListHolder holder, int position) {

        holder.hotlistText.setText(data.get(position).getHotlistText());

        holder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (null !=listener){
                    listener.onItemClick(position);
                }
            }
        });


    }

    @Override
    public int getItemCount() {
        return null != data ? data.size() : 0;
    }



    class HotListHolder extends RecyclerView.ViewHolder{
        TextView hotlistText;

        public HotListHolder(@NonNull  View itemView) {
            super(itemView);
            hotlistText = itemView.findViewById(R.id.Homeft_Hot_list_text);
        }
    }
    public interface OnRecyclerViewItemClickListener{


        void onItemClick(int position);
    }

}
